/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { Input, InputFile, TaskDetails } from '@ohos/hvigor';
import path from 'path';

import { BuildArtifactConst } from '../../const/build-directory-const.js';
import { DebugSymbol, NativeLib } from '../../options/build/build-opt.js';
import { AbstractBuildNative } from '../abstract-build-native.js';

import { TargetTaskService } from '../service/target-task-service.js';

/**
 * CacheNativeLibs和DoNativeStrip的抽象父类
 *
 * @since 2023/11/30
 */
export abstract class AbstractNativeStrip extends AbstractBuildNative {
  protected readonly nativeLibOption: NativeLib | undefined;
  @Input() protected readonly debugSymbol: DebugSymbol | undefined;
  protected readonly exclude: string[] | undefined;
  @InputFile({ isDirectory: true }) protected readonly intermediatesProcessLibs: string;
  protected readonly strippedNativeLibs: string;
  protected readonly moduleBuildPath: string;
  protected readonly cacheFilePath: string;

  protected constructor(targetService: TargetTaskService, taskDetails: TaskDetails) {
    super(targetService, taskDetails);
    this.nativeLibOption = targetService.getBuildOption()?.nativeLib;
    this.debugSymbol = this.nativeLibOption?.debugSymbol;
    this.exclude = this.debugSymbol?.exclude;

    // 获取目标lib路径
    this.intermediatesProcessLibs = this.pathInfo.getIntermediatesProcessLibs();
    this.strippedNativeLibs = this.pathInfo.getIntermediatesStrippedLibsDir();
    this.moduleBuildPath = this.pathInfo.getModuleBuildPath();
    this.cacheFilePath = path.resolve(this.pathInfo.getIntermediatesPatch(), BuildArtifactConst.BASE_NATIVE_LIBS_JSON);
  }
}
